package hk.gov.edb.edis.json.impl;

import hk.gov.edb.edis.json.interfaces.JSONUtil;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DefaultGSONUtilImpl implements JSONUtil{ 
	/*
	protected DefaultGSONUtilImpl instance;
	
	private DefaultGSONUtilImpl(){
		gson = new GsonBuilder().setPrettyPrinting().create();
	}
	
	public DefaultGSONUtilImpl instanceOf(){
		if (instance==null){
			instance = new DefaultGSONUtilImpl();
		}
		
		return instance;
	}
*/	

	
	
	protected Gson gson;

	public DefaultGSONUtilImpl(){
		gson = new GsonBuilder().setPrettyPrinting().create();
	}
	
	public String toJSON(Object obj){
		return gson.toJson(obj);
	}
	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Object fromJSON(String jsonString, Class objType){
		return gson.fromJson(jsonString, objType);
	}
	
}
